<?php    
    $manager_object = new manager();

    //action对应表
    $action_ary = array(
    'edit' => 'admin_act_edit',    
    'pwd'  => 'admin_act_update_pwd',    		
    );

    //执行函数
    if($action && ($fun = $action_ary[$action])){
        $fun();
    }

    //action
    //*+------------------------------------------------------------------------+*/

    /**
    * 管理员修改账号
    * @author leiqianyong 2016-12-20 13:48 PM
    */
    function admin_act_edit() {
        global $manager_object;

        $rtn=array('state'=>false);
        
        //验证是否登录
        $aid=is_cookie_login();
        if(!$aid){
        	$rtn['msg']='请登录';        	        	
        	exit(json_encode($rtn));        	 
        }
        
        $name=request('name');
        if(!$name){
        	$rtn['msg']='请输入姓名';        	
        	exit(json_encode($rtn));        	 
        }
        
        if(strlen($name)>30){
        	$rtn['msg']='姓名输入过长';
        	exit(json_encode($rtn));        	 
        }
        
        //电话号码
        $phone=request('phone');               
        if(!is_mobile($phone)){
        	$rtn['msg']='请输入手机号码';
        	exit(json_encode($rtn));
        }
        
        //邮箱
        $email=request('email',false,false,true);
        if(!$email){
        	$rtn['msg']='请输入邮箱号码';
        	exit(json_encode($rtn));        	
        }
        
        $sex=request('sex',false,true,false,1);
        $data=compact('name','phone','email','sex');       
        
        $res=$manager_object->admin_edit($aid, $data);
        
        if(!$res){
        	$rtn['msg']='修改失败';
        	exit(json_encode($rtn));          	
        }
        
        $rtn['msg']='修改成功';
        $rtn['state']=true;
        $rtn['url']='/mobile/center';
        exit(json_encode($rtn));
    }

   
    /**
     * 修改密码
     *
     * @author limin 2012-8-21 PM 14:46:05
     */
    function admin_act_update_pwd() {
        global $manager_object;

        $rtn=array('state'=>false);
        
        //验证是否登录
        $aid=is_cookie_login();
        if(!$aid){
        	$rtn['msg']='请登录';        	        	
        	exit(json_encode($rtn));        	 
        }
                  
    	//原始密码
    	$oldpwd = request('oldpwd');
    	if(!$oldpwd){
    		$rtn['msg']='请输入旧密码';
    		exit(json_encode($rtn));    		
    	}
    	
    	$admininfo=$manager_object->admin_info('password');
    	if($admininfo['password']!=md5($oldpwd)){
    		$rtn['msg']='旧密码不正确';
    		exit(json_encode($rtn));    		
    	}
    
    	//新密码
    	$password = request('newpwd');
    	if(!$password){
    		$rtn['msg']='请输入新密码';
    		exit(json_encode($rtn));
    	}    	
    
    	//确认密码
    	$repwd = request('repwd');
    	if($repwd!=$password){
    		$rtn['msg']='确认码不正确';
    		exit(json_encode($rtn));
    	}    	
    	
    	$data['password']=md5($repwd);
    	$res=$manager_object->admin_edit($aid, $data);
    	if(!$res){
    		$rtn['msg']='操作失败';
    		exit(json_encode($rtn));    		
    	}
    
    	$rtn['msg']='操作成功';
    	$rtn['state']=true;
    	exit(json_encode($rtn));    		    	
    }    
    

    /**
    * 退出系统
    * 
    * @author limin 2012-8-21 PM 14:43:01
    */
    function admin_act_quit() {
        global $admin_object;
        $admin_object->_quit();                        
        location_msg('2007', '/');        
    }



    /**
    * 修改注册用户状态，禁用还是启用
    * @author  limin 2012-8-23      AM 10:58:00
    */
    function admin_act_update_user_state() {  
        global $admin_object;

        //注册用户ID
        $id = request('id',false,true);

        //用户状态，禁用还是启用
        $banned = request('banned',false,true);
        if(!$id) {
            return false;    
        }

        if(!$admin_object->_update_user_state($id,$banned)) {
            location_msg('2015');    //用户状态修改失败
        }
        location_msg('2014');     //用户状态修改成功

    }

    /**
    * 修改管理用户状态，禁用还是启用
    * @author  limin 2012-8-23      AM 10:58:00
    */
    function admin_act_update_admin_state() {  
        global $admin_object;

        //用户ID
        $id = request('id',false,true);

        //用户状态，禁用还是启用
        $banned = request('banned',false,true); 
        if(!$id) {
            return false;    
        }

        if(!$admin_object->_update_admin_state($id, $banned)) {
            location_msg('2018');    //管理员状态修改失败
        }
        location_msg('2017');     //管理员状态修改成功

    }

    /**
    * 管理员检查是否存在
    * 
    * @author zhouqi 2012-9-7 PM 06:32:52
    */
    function admin_act_check() {
        global $admin_object;

        //管理员账户
        $account = request('account');
        
        $rtn = array('state' => false);                    

        if($admin_object->_info_account($account)) {
            echo_json($rtn);
        }
        $rtn['state'] = true;
        echo_json($rtn);
    }

    //function
    //*+------------------------------------------------------------------------+*/

    /**
    * 获取管理员资料
    * 
    * @author limin 2012-8-21 PM 14:56:38
    */
    function admin_fun_info($id) {
        global $admin_object;
        $id=intval($id);

        if(!$id) {
            return false;
        }

        return $admin_object->_info_by_id($id);
    }

    /**
    * 根据账户查找管理员信息
    * @author limin 2012-8-21 PM 14:56:38
    * @param   mixed $account 账户名
    */
    function admin_fun_info_account($account) {
        global $admin_object;
        if(!$account)
        {
            return false;    
        }
        return $admin_object->_info_account($account);
    }

    /**
    * 获取管理员ID
    * 
    * @author limin 2012-8-21 PM 14:57:08
    */
    function admin_fun_get_id() {
        global $admin_object;
        return $admin_object->_id();
    }


    /**
    * 获取所有管理员信息
    * 
    * @author limin 2012-8-22 AM 10:15:38
    */
    function admin_fun_list($page=1,$size=10) {
        global $admin_object;
        return $admin_object->_list($page,$size);
    }

    /**
    * 获取管理员缓存信息
    * 
    * @author limin 2012-8-21 PM 15:00:54
    */
    function admin_fun_cache_info() {
        global $admin_object;
        return $admin_object->cache_info();
    } 

    /**
    * 根据用户ID获取用户资料
    * 
    * @author zhouqi 2012-9-7 PM 05:16:06
    * @param int $id   ID
    */
    function admin_fun_user_info($id) {
        global $admin_object;

        $id = intval($id);
        if(!$id) {
            return false;
        }

        return $admin_object->_user_info($id);
    }

    /**
    * 获得所有注册用户信息
    * 
    * @author zhouqi 2012-9-7 PM 04:12:01
    * @param int $page
    * @param int $pagesize
    * @param array $where
    * @param string $ord
    */
    function admin_fun_user_list($page = 1, $pagesize = 10, $where = '', $ord = ''){
        global $admin_object;

        $page = intval($page);
        $pagesize = intval($pagesize);

        if(!$page || !$pagesize) {
            return false;
        }

        return $admin_object->_user_list($page, $pagesize, $where, $ord);
    }

    /**
    * 获得学院信息
    * 
    * @author leiqianyong 2012-9-8 PM 04:12:01
    */
    function admin_fun_area(){
        global $admin_object;

        return $admin_object->getarea();
    }    

    /**
    * 获得面包屑导航
    * @author limin 2012-8-29 PM 15:04:00
    * @param  string $key  功能键值
    */
    function admin_fun_crumbs_menu($key){        
        global $admin_object,$_site;         

        //功能分割
        $key_ary = explode('-', $key);

        $str = '';

        $fun = $_site->data_config['fun'];

        if(!array_key_exists($key_ary[0], $fun)) {
            return false;
        }        

        $str = $fun[$key_ary[0]]['title'] . ' &gt; ' . 
        $fun[$key_ary[0]]['list']["{$key_ary[0]}-{$key_ary[1]}"]['title'] . ' &gt; ' .
        $fun[$key_ary[0]]['list']["{$key_ary[0]}-{$key_ary[1]}"]['list']["{$key_ary[0]}-{$key_ary[1]}-{$key_ary[2]}"]['title'];

        return $str;
    }


    function admin_fun_env() {

    }

    /**
    * 当前数据库大小
    * 
    * @author zhouqi 2012-9-11 PM 04:42:58
    */
    function admin_fun_db_size() {
        global $admin_object;
        return $admin_object->_database_size();
    }
?>